<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员仪表板</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        h1, h2 {
            color: #333;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .action-buttons {
            display: flex;
            gap: 10px;
        }
        button, a.button {
            padding: 8px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
        }
        .btn-backup {
            background-color: #4CAF50;
            color: white;
        }
        .btn-import {
            background-color: #2196F3;
            color: white;
        }
        .btn-ban {
            background-color: #f44336;
            color: white;
        }
        .btn-reset-password {
            background-color: #9c27b0;
            color: white;
        }
        .btn-delete {
            background-color: #f44336;
            color: white;
        }
        .btn-view-shared {
            background-color: #00bcd4;
            color: white;
        }
        .btn-unban {
            background-color: #4caf50;
            color: white;
        }
        .btn-authorization {
            background-color: #ff9800;
            color: white;
            margin-top: 20px;
        }
        .flash {
            padding: 10px;
            margin-bottom: 15px;
            border-radius: 4px;
        }
        .flash.success {
            background-color: #dff0d8;
            color: #3c763d;
        }
        .flash.error {
            background-color: #f2dede;
            color: #a94442;
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .logout-button {
            background-color: #f44336;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>管理员仪表板</h1>

<a href="{{ url_for('blacklist') }}" style="display: inline-block; margin-bottom: 20px; padding: 10px 15px; background-color: #2196F3; color: white; text-decoration: none; border-radius: 4px;">查看IP黑名单</a>
            <a href="{{ url_for('logout') }}" class="button logout-button">退出登录</a>
        </div>

        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="flash {{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <h2>用户管理</h2>
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                    <tr>
                        <td>{{ user.id }}</td>
                        <td>{{ user.username }}</td>
                        <td>{{ user.email }}</td>
                        <td>{{ '已封禁' if user.is_banned else '正常' }}</td>
                        <td class="action-buttons">
                            <a href="{{ url_for('backup_user', user_id=user.id) }}" class="button btn-backup">备份</a>
                            <a href="{{ url_for('import_user_data', user_id=user.id) }}" class="button btn-import">导入</a>
                            <a href="{{ url_for('reset_user_password', user_id=user.id) }}" class="button btn-reset-password" onclick="return confirm('确定要重置该用户密码吗？');">重置密码</a>
                            <a href="{{ url_for('delete_user', user_id=user.id) }}" class="button btn-delete" onclick="return confirm('确定要删除该用户吗？');">删除用户</a>
                            <a href="{{ url_for('user_shared_files', user_id=user.id) }}" class="button btn-view-shared">查看分享文件</a>
                            {% if not user.is_banned %}
                                <a href="{{ url_for('ban_user', user_id=user.id) }}" class="button btn-ban" onclick="return confirm('确定要封禁该用户吗？');">封禁</a>
                            {% else %}
                                <a href="{{ url_for('unban_user', user_id=user.id) }}" class="button btn-unban" onclick="return confirm('确定要解除该用户的封禁吗？');">解除封禁</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

        <h2>系统设置</h2>
        <a href="{{ url_for('update_email_authorization') }}" class="button btn-authorization">修改邮箱客户端授权码</a>
    </div>
</body>
</html>